import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
import 'package:top_foundation/component/popup/popup.dart';
import 'package:top_foundation/utils/theme/theme.dart';

import 'helper/route/router_config.dart';

import 'helper/utils/methodchannelmanager.dart';

import 'package:flutter_localizations/flutter_localizations.dart';

import 'helper/utils/util.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual,
      overlays: [SystemUiOverlay.bottom, SystemUiOverlay.top]);
  MethodChannelManager.initChannel();
  // JPushMan().initJpush();
  // WXUtil().register();
  TopConfig.imgPlaceholder = 'appIcon.png'.imgPath;
  TopConfig.imgDefaultAvater = 'avater.png'.imgPathMe;

  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key);
  DateTime? lastTime;
  @override
  Widget build(BuildContext context) {
    return ScreenAdapterInit(
        designSize: const Size(393, 844),
        builder: (context) => RefreshConfiguration(
              hideFooterWhenNotFull: true, //列表数据不满一页,不触发加载更多
              child: GetMaterialApp(
                theme: ITheme.theme,
                initialRoute: RouterPath.splash,
                onGenerateRoute: MyRouterConfig.generateRoute,
                // navigatorObservers: [UmengAppAnalysis(), ],
                getPages: RouterPages.getPages,
                localizationsDelegates: const [
                  RefreshLocalizations.delegate,
                  GlobalMaterialLocalizations.delegate,
                  GlobalWidgetsLocalizations.delegate,
                  GlobalCupertinoLocalizations.delegate, //iOS
                ],
                supportedLocales: const [
                  Locale('zh', 'CN'),
                  Locale('en', 'US'),
                ],
                builder: (context, child) {
                  child = Popup.init(context, child);
                  child = Hud.init(context, child);
                  child = MediaQuery(
                      //设置文字大小不随系统设置改变
                      data:
                          MediaQuery.of(context).copyWith(textScaleFactor: 1.0),

                      //全局设置键盘收缩
                      child: GestureDetector(
                        onTap: () {
                          FocusScopeNode focus = FocusScope.of(context);
                          if (!focus.hasPrimaryFocus &&
                              focus.focusedChild != null) {
                            FocusManager.instance.primaryFocus?.unfocus();
                          }
                        },
                        child: child,
                      ));
                  return child;
                },
              ),
            ));
  }
}
